package com.janko.redislock.redisLock.controller.service;

import com.janko.redislock.redisLock.annotation.DistributedLock;

import java.util.concurrent.TimeUnit;

public class OrderServices {

    @DistributedLock(value = "redisLockRegistry",time = 10)
    public String grabOrder(int orderId, int driverId) {

        System.out.println("司机:" + driverId + " 执行抢单逻辑");
        try {
            TimeUnit.MINUTES.sleep(5);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }

//        boolean b = orderService.grab(orderId, driverId);
        boolean b=grab(orderId,driverId);
        if (b) {
            System.out.println("司机:" + driverId + " 抢单成功");
        } else {
            System.out.println("司机:" + driverId + " 抢单失败");
        }

        return null;
    }

    private boolean grab(int orderId, int driverId) {
        return true;
    }
}
